const Router = require('koa-router');
const db = require('../libs/db');
const response = require('../libs/result');
let router = new Router();


/**
 * @api {post} /api/v1/featured/query  获取广告
 * @apiDescription 获取广告
 * @apiName query
 * @apiParam (参数) {String} type  广告类型    0 首页滚动banner    1 首页业务介绍   2   推荐页营销活动   3 闪屏页    4 首页弹窗广告   5   浮标   
 * @apiSampleRequest /api/v1/featured/query
 * @apiGroup featured
 * @apiVersion 1.0.0
 */
router.post('/query', async ctx => {
    let { type, link_type, country_id } = ctx.request.body;
    let selectStr = ' * ';
    let whereObj = {
        country_id:ctx.config.country_id
    };
    if (type || type == 0) {
        whereObj.type = type;
    }
    // if (link_type || link_type == 0) {
    //     whereObj.link_type = link_type;
    // }
    // if (country_id || country_id == 0) {
    //     whereObj.country_id = country_id;
    // }
    let data = await db.querylist(ctx, 'featured_featured', selectStr, whereObj);
    if(data.length>0){
        data.map(function (item,index,input) {
          item.images=ctx.config.fileurl+item.images;
      })
      }
      response(ctx, 200, data, '广告列表');
})

module.exports = router.routes()